package com.qyhl.webtv.module_microvideo.shortvideo.introduction;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.microvideo.ShortVideoIntroductionBean;
import com.qyhl.webtv.module_microvideo.common.VideoUrl;

public class ShortVideoIntroductionModel implements ShortVideoIntroductionContract.ShortVideoIntroductionModel {
    private ShortVideoIntroductionPresenter mPresenter;

    ShortVideoIntroductionModel(ShortVideoIntroductionPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getDetail(String actId) {

        EasyHttp.get(VideoUrl.GET_SHORT_VIDEO_INTRODUCTION)
                .params("actId", actId)
                .params("siteId", CommonUtils.getInstance().getSite()+"")
                .execute(new SimpleCallBack<ShortVideoIntroductionBean>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容，请稍后再试！");
                        } else {
                            mPresenter.setError("请求失败，请重新获取！");
                        }
                    }

                    @Override
                    public void onSuccess(ShortVideoIntroductionBean shortVideoIntroductionBean) {
                        if (shortVideoIntroductionBean != null) {
                            mPresenter.setDetail(shortVideoIntroductionBean);
                        } else {
                            mPresenter.setError("暂无任何内容，请稍后再试！");
                        }
                    }
                });
    }
}
